import type { Category } from '@/types'

// 模拟分类数据
const mockCategories: Category[] = [
  { id: '1', name: '电影', description: '电影相关视频', count: 15, createdAt: '2024-01-01' },
  { id: '2', name: '音乐', description: '音乐和MV', count: 28, createdAt: '2024-01-01' },
  { id: '3', name: '教育', description: '教学和培训视频', count: 42, createdAt: '2024-01-01' },
  { id: '4', name: '新闻', description: '新闻和资讯', count: 18, createdAt: '2024-01-01' },
  { id: '5', name: '娱乐', description: '娱乐节目', count: 23, createdAt: '2024-01-01' }
]

// 模拟API延迟
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

export const categoryApi = {
  // 获取分类列表
  async getCategories(): Promise<Category[]> {
    await delay(300)
    return [...mockCategories]
  },

  // 创建分类
  async createCategory(data: Omit<Category, 'id' | 'count' | 'createdAt'>): Promise<Category> {
    await delay(500)
    const newCategory: Category = {
      id: Date.now().toString(),
      count: 0,
      createdAt: new Date().toISOString().split('T')[0],
      ...data
    }
    mockCategories.push(newCategory)
    return newCategory
  },

  // 更新分类
  async updateCategory(id: string, data: Partial<Category>): Promise<Category | null> {
    await delay(500)
    const index = mockCategories.findIndex(cat => cat.id === id)
    if (index > -1) {
      mockCategories[index] = { ...mockCategories[index], ...data }
      return mockCategories[index]
    }
    return null
  },

  // 删除分类
  async deleteCategory(id: string): Promise<boolean> {
    await delay(500)
    const index = mockCategories.findIndex(cat => cat.id === id)
    if (index > -1) {
      mockCategories.splice(index, 1)
      return true
    }
    return false
  }
} 